home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 7.7 KB | 312 lines | [TEXT/MMCC] |
- /*
- ** File: CFilterControl.cp
- ** Written by: Tim Nufire
- **
- ** Copyright © 1990-1995 Apple Computer, Inc.
- ** All rights reserved. */
-
- /*****************************************************************************/
- /* This is a custom Filter slider. */
- /*****************************************************************************/
-
-
- #include "CFilterControl.h"
- #include "CSoundboardApp.h"
-
- #include "FilterComponent.h"
-
- #include <UAppleEventsMgr.h>
- #include <UExtractFromAEDesc.h>
- #include <LModelProperty.h>
-
- #ifndef __AEPACKOBJECT__
- #include <AEPackObject.h>
- #endif
-
- #ifndef __AEOBJECTS__
- #include <AEObjects.h>
- #endif
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
-
- // ---------------------------------------------------------------------------
- // • CreateFilterControlStream [static]
- // ---------------------------------------------------------------------------
- // Create a new FilterControl from the data in a Stream
- //
- // Current port must be the Window into which to install the control
-
- CFilterControl*
- CFilterControl::CreateFilterControlStream(
- LStream *inStream)
- {
- return (new CFilterControl(inStream));
- }
-
- // ---------------------------------------------------------------------------
- // • FilterControl(LStream*)
- // ---------------------------------------------------------------------------
- // Construct SliderControl from a data stream
-
- CFilterControl::CFilterControl(
- LStream *inStream)
- : CSliderControl(inStream)
- {
- mLabel = 0;
- mLabelChanges = 0;
-
- SetModelKind(cSlider);
- SetUseSubModelList(false);
- }
-
- // ---------------------------------------------------------------------------
- // • ~FilterControl
- // ---------------------------------------------------------------------------
- // Destructor
-
- CFilterControl::~CFilterControl()
- {
- }
-
-
- // ===========================================================================
- // • AppleEvent Object Model Support AppleEvent Object Model Support •
- // ===========================================================================
-
-
- void
- CFilterControl::GetAEProperty(
- DescType inProperty,
- const AEDesc &inRequestedType,
- AEDesc &outPropertyDesc) const
- {
- OSErr err;
-
- switch (inProperty) {
-
- case pValue:
- Int32 theValue = GetValue();
- err = AECreateDesc(typeLongInteger, (Ptr) &theValue,
- sizeof(Int32), &outPropertyDesc);
- break;
-
- case pMaxValue:
- Int32 theMaxValue = GetMaxValue();
- err = AECreateDesc(typeLongInteger, (Ptr) &theMaxValue,
- sizeof(Int32), &outPropertyDesc);
- break;
-
- case pName: // Slider Title
- Str255 theName;
- GetDescriptor(theName);
- err = ::AECreateDesc(typeChar, (Ptr) theName + 1,
- StrLength(theName), &outPropertyDesc);
- break;
-
- case pLabel: // Slider Label
- if (mLabel) {
- Str255 theLabel;
- mLabel->GetDescriptor(theLabel);
- err = ::AECreateDesc(typeChar, (Ptr) theLabel + 1,
- StrLength(theLabel), &outPropertyDesc);
- }
- else LModelObject::GetAEProperty(inProperty, inRequestedType,
- outPropertyDesc);
- break;
-
- case pBounds: // Frame in local coords
- Rect theBounds;
- CalcLocalFrameRect(theBounds);
- err = ::AECreateDesc(typeQDRectangle, (Ptr) &theBounds,
- sizeof(Rect), &outPropertyDesc);
- break;
-
- case pIndex: // Front-to-back position index
- Int32 thePosition = mSuperModel->GetPositionOfSubModel(cSlider, this);
- err = ::AECreateDesc(typeLongInteger, (Ptr) &thePosition,
- sizeof(Int32), &outPropertyDesc);
- break;
-
- case pVisible:
- Boolean isVis = IsVisible();
- err = AECreateDesc(typeBoolean, (Ptr) &isVis,
- sizeof(Boolean), &outPropertyDesc);
- break;
-
- default:
- LModelObject::GetAEProperty(inProperty, inRequestedType,
- outPropertyDesc);
- break;
- }
- }
-
-
- void
- CFilterControl::SetAEProperty(
- DescType inProperty,
- const AEDesc &inValue,
- AEDesc& outAEReply)
- {
- switch (inProperty) {
- case pValue:
- Int32 theValue;
- UExtractFromAEDesc::TheInt32(inValue, theValue);
- SliderAction(theValue);
- SetValue(theValue);
- break;
-
- case pMaxValue:
- Int32 theMaxValue;
- UExtractFromAEDesc::TheInt32(inValue, theMaxValue);
- SetMaxValue(theMaxValue);
- break;
-
- case pName:
- Str255 theName;
- UExtractFromAEDesc::ThePString(inValue, theName);
- SetDescriptor(theName);
- break;
-
- case pLabel:
- if (mLabel) {
- Str255 theLabel;
- UExtractFromAEDesc::ThePString(inValue, theLabel);
- mLabel->SetDescriptor(theLabel);
- mLabel->Refresh();
- }
- else LModelObject::SetAEProperty(inProperty, inValue, outAEReply);
- break;
-
- case pBounds:
- Rect theNewBounds, theOldBounds;
- UExtractFromAEDesc::TheRect(inValue, theNewBounds);
- CalcLocalFrameRect(theOldBounds);
- MoveBy(theNewBounds.left-theOldBounds.left, theNewBounds.top-theOldBounds.top, true);
- ResizeFrameBy((theNewBounds.right-theNewBounds.left) - (theOldBounds.right - theOldBounds.left),
- (theNewBounds.bottom-theNewBounds.top) - (theOldBounds.bottom - theOldBounds.top),
- true);
- break;
-
- case pVisible:
- Boolean makeVisible;
- UExtractFromAEDesc::TheBoolean(inValue, makeVisible);
- if (makeVisible) {
- Show();
- if (mLabel) mLabel->Show();
- } else {
- Hide();
- if (mLabel) mLabel->Hide();
- }
- break;
-
- default:
- LModelObject::SetAEProperty(inProperty, inValue, outAEReply);
- break;
- }
- }
-
-
- void
- CFilterControl::HandleAppleEvent(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult,
- long inAENumber)
- {
- Int32 value;
- StAEDescriptor valDesc;
-
- switch (inAENumber) {
-
- case ae_SetValue:
- /* valDesc.GetParamDesc(inAppleEvent, keyDirectObject, typeLongInteger);
- UExtractFromAEDesc::TheInt32(valDesc.mDesc, value);
-
- SetValue(value);
- */
- SysBeep(10);
- break;
-
- case ae_SetMax:
- valDesc.GetParamDesc(inAppleEvent, keyDirectObject, typeLongInteger);
- UExtractFromAEDesc::TheInt32(valDesc.mDesc, value);
-
- SetMaxValue(value);
- break;
-
- default:
- LModelObject::HandleAppleEvent(inAppleEvent, outAEReply,
- outResult, inAENumber);
- break;
- }
- }
-
-
- // ===========================================================================
- // • Sending Apple Events Sending Apple Events •
- // ===========================================================================
-
- // ---------------------------------------------------------------------------
- // • SendAESetValue
- // ---------------------------------------------------------------------------
- // AppleEvent for setting the value of a slider
-
- void
- CFilterControl::SendAESetValue(
- Int32 value,
- Boolean inExecute)
- {
- LModelProperty valueProperty(pValue, this, false);
- valueProperty.SendSetDataAE(typeLongInteger, (Ptr) &value,
- sizeof(Int32), inExecute);
- }
-
-
- // ---------------------------------------------------------------------------
- // • SendAESetMax
- // ---------------------------------------------------------------------------
- // AppleEvent for setting the Max of a slider
-
- void
- CFilterControl::SendAESetMax(
- Int32 max)
- {
- LModelProperty maxValueProperty(pMaxValue, this, false);
- maxValueProperty.SendSetDataAE(typeLongInteger, (Ptr) &max,
- sizeof(Int32), false);
- }
-
-
- void
- CFilterControl::TrackSlider(Point origMouseLoc)
- {
- short gainIndex = GetPaneID()-FirstSliderID;
-
- CSliderControl::TrackSlider(origMouseLoc);
-
- SliderAction((*mMacControlH)->contrlValue);
- SendAESetValue((*mMacControlH)->contrlValue);
- }
-
- void
- CFilterControl::SliderAction(short newPos)
- {
- short gainIndex = GetPaneID()-FirstSliderID;
-
- if (CSoundboardApp::mFilterInstance)
- {
- double curGain, newGain = ((double)kMaxGain - newPos)/kMaxGain;
-
- DoGetGain (CSoundboardApp::mFilterInstance, gainIndex, &curGain);
-
- if (curGain != newGain)
- DoSetGain (CSoundboardApp::mFilterInstance, gainIndex, &newGain);
- }
-
- CSoundboardApp::mGainValue[gainIndex] = newPos;
- }
-
-